# Time  ：2021/5/28 7:47
# Author：Houtaroy
from flask_koala.core.database import db
from flask_koala.core.swagger import blueprint, swagger
from flask_koala.core.encoders import KoalaJSONEncoder
from flask_koala.core.exceptions import BusinessException, business_exception_handler
from flask_koala.auth import jwt, apis as auth_apis
from flask_koala.system import user_api


class Koala:
    def __init__(self, app=None):
        self.app = app
        if app is not None:
            self.init_app(app)

    def init_app(self, app):
        db.init_app(app)
        jwt.init_app(app)
        swagger.add_namespace(auth_apis)
        swagger.add_namespace(user_api)
        app.register_blueprint(blueprint)
        app.json_encoder = KoalaJSONEncoder
        app.register_error_handler(BusinessException, business_exception_handler)
